/**
 * array utilities
 * Copyright (c) 2009 cmiscm.com
 * date of final modification : 2009. 12. 17 
*/
package com.cmiscm.utils.common
{
	import flash.utils.ByteArray;
	
	/**
	 * Array Utilities.
     * 
     */
	public class ArrayUtilities
	{
		/**
		 * Copy array
		 * @param $array Array
		 * @return 
		 * 
		 */			
		public static function copyArray($array:Array):Array 
		{
			var byte:ByteArray = new ByteArray();
			byte.writeObject($array);
			byte.position = 0;
			var result:Array = byte.readObject();
			return result;
		}
		
		/**
		 * Shuffle array
		 * @param $array Array
		 * @return 
		 * 
		 */			
		public static function shuffle($array:Array):Array		
		{
			var arr_tmp:Array = $array;
			var len:int = $array.length;
			for (var i:int=0; i<len; i++) {
				var x:int = NumberUtilities.random(0, len - 1);
				var y:int = NumberUtilities.random(0, len - 1);
				var z:Object = arr_tmp[x];
				arr_tmp[x] = arr_tmp[y];
				arr_tmp[y] = z;
			}
			return arr_tmp;
		}
	}
}